package com.cloud.bssp.java8.lambda;

import lombok.Data;

import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @description： 方法引用
 * @author：weirx
 * @date：2021/10/19 17:07
 * @version：3.0
 */
public class MethodReference {
    @Data
    static class Student{
        private String name;
        private Integer age;

        public Student(String name, Integer age) {
            this.name = name;
            this.age = age;
        }
    }

    public static void main(String[] args) {
        //静态方法引用，parseInt
        Function<String, Integer> function = Integer::parseInt;
        Integer apply = function.apply("100");
        System.out.println(apply);

        //指向任意实例类型方法
        Function<String,Integer> function1 = String::length;
        Integer hello_world = function1.apply("hello world");
        System.out.println(hello_world);

        //指向现有对象实例的方法
        Student student = new Student("Jack",10);
        Supplier<String> supplier = student::getName;
        String s = supplier.get();
        System.out.println(s);
    }
}
